package com.shanzhe.eshop.common.jdk;

import lombok.SneakyThrows;

import java.util.concurrent.CyclicBarrier;

/**
 * @Author yinwei
 * @create 2021/12/13
 * @Version 1.0
 */
public class CycliyBarrierDemo {

    public static void main(String[] args) {
      final   CyclicBarrier cyclicBarrier = new CyclicBarrier(2, new Runnable() {
            @Override
            public void run() {
               System.out.println("77777777777");
            }
        });

        new Thread(){
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(1000);
                System.out.println("线程1执行。。。。");
                cyclicBarrier.await();
            }
        }.start();

        new Thread(){
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(1000);
                System.out.println("线程2执行。。。。");
                cyclicBarrier.await();
            }
        }.start();
    }
}
